home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Media Design Review 1999
/
Interactive Media Design Review 1999.iso
/
pc
/
Demos
/
Herois
/
Codigo.Cst
/
00048_Script_DB Tools
< prev
next >
Wrap
Text File
|
1999-03-19
|
6KB
|
218 lines
on fazDB
v12DB
importaDB
end
on importaDB
put "Importando arquivos ..."
importaArquivos
put "Importando palavras ..."
importaPalavras
put "Importando referencias ..."
importaReferencias
end
on v12DB
fechaDB
set f = new(xtra "fileio")
openFile(f,the moviePath & "search.v12", 2)
delete(f)
closeFile(f)
set f = 0
put "Criando banco de dados ..."
criaDB
end
on criaDB
Set ClassDbe = Xtra "V12Dbe"
set dbObj = new(ClassDbe,the moviePath & "search.v12","Create","no")
if NOT objectP(dbObj) then
Alert("Cannot create database: search.v12")
exit
end if
mCreateTable(dbObj,"palavras" )
mCreateField(dbObj,"palavras","palNum","Integer")
mCreateField(dbObj,"palavras","palavra","String",48)
mCreateField(dbObj,"palavras","canonica", "String", 48)
mCreateIndex(dbObj,"palavras","palNdx","U","canonica","A")
mCreateTable(dbObj,"arquivos" )
mCreateField(dbObj,"arquivos","arqNum","Integer")
mCreateField(dbObj,"arquivos","arquivo","String",224)
mCreateIndex(dbObj,"arquivos","arqNdx","duplicate","arqNum","A")
mCreateIndex(dbObj,"arquivos","alfaNdx","D","arquivo","A")
mCreateTable(dbObj,"referencias" )
mCreateField(dbObj,"referencias","palNum","Integer")
mCreateField(dbObj,"referencias","mediaNum", "Integer")
mCreateField(dbObj,"referencias","arqNum","Integer")
mCreateIndex(dbObj,"referencias","refNdx","D","palNum","A")
mBuild(dbObj)
set dbObj = 0
set ClassDbe = 0
end
on abreDB
global V12dbeFact, V12tblFact
global gDB, gPals, gRefs, gArqs
set gDB = new(V12dbeFact, the moviePath & "search.v12", "ReadOnly", "no")
set gPals = new(V12tblFact, mGetRef(gDB), "palavras")
set gArqs = new(V12tblFact, mGetRef(gDB), "arquivos")
set gRefs = new(V12tblFact, mGetRef(gDB), "referencias")
end
on fechaDB
global gDB, gPals, gRefs, gArqs
set gDB = 0
set gPals = 0
set gRefs = 0
set gArqs = 0
end
on leAteFimDeLinha arq
set pal to ""
-- Tira espaco inicial
set c to numToChar(10)
repeat while c = numToChar(10)
put readChar(arq) into c
end repeat
-- Pega palavra
repeat while c <> numToChar(10) and c <> numToChar(0)
put pal & c into pal
put readChar(arq) into c
end repeat
return pal
-- put readLine(arq) into pal
-- put char 1 to length(pal)-1 of pal into pal
-- return pal
end
on importaPalavras
Set ClassDbe = Xtra "V12Dbe"
set dbObj = new(ClassDbe,the moviePath & "search.v12","ReadWrite","no")
if NOT objectP(dbObj) then
Alert("Cannot open database: search.v12")
exit
end if
set ClassTable = Xtra "V12Table"
set tbl = new(ClassTable,mGetRef(dbObj),"palavras")
set f = new(xtra "fileio") -- Create an instance of FileIO
openFile(f, the moviePath & "Convertidos/palavras.txt", 1) -- Open the file
set fLen = getLength(f)
set counter = 0
repeat while ( getPosition(f) < fLen-2)
-- Le registro
set num = leAteFimDeLinha(f)
set pal = leAteFimDeLinha(f)
set can = leAteFimDeLinha(f)
if rollOver(4) then put can & " " & pal & " " & num
-- Guarda no banco de dados
mAddRecord(tbl)
mSetField(tbl,"canonica", can)
mSetField(tbl,"palavra", pal)
mSetField(tbl,"palNum", num)
mUpdateRecord(tbl)
-- Incrementa contador
set counter = counter + 1
if counter mod 1000 = 0 then put counter & " " & "registros"
end repeat
put "Palavras " & counter
mGoFirst(tbl)
mSelect(tbl)
put "Palavras total: " & mSelectCount(tbl)
closeFile(f)
set f = 0
set tbl = 0
set dbObj = 0
set ClassDbe = 0
end
on importaArquivos
put " Arquivos: abrindo banco de dados"
Set ClassDbe = Xtra "V12Dbe"
set dbObj = new(ClassDbe,the moviePath & "search.v12","ReadWrite","no")
if NOT objectP(dbObj) then
Alert("Cannot open database: search.v12")
exit
end if
set ClassTable = Xtra "V12Table"
set tbl = new(ClassTable,mGetRef(dbObj),"arquivos")
put " Arquivos: removendo registros antigos"
mSelectAll(tbl)
mSelDelete(tbl)
put " Arquivos: abrindo arquivo de entrada"
set f = new(xtra "fileIO")
openFile(f, the moviePath & "Convertidos/arquivos.txt",1)
set fLen = getLength(f)
set counter = 0
repeat while (getPosition(f) < fLen-2)
set num to leAteFimDeLinha(f)
set arq to leAteFimDeLinha(f)
mAddRecord(tbl)
mSetField(tbl,"arquivo", arq)
mSetField(tbl,"arqNum", num)
mUpdateRecord(tbl)
set counter = counter + 1
end repeat
put "Arquivos " & counter
mGoFirst(tbl)
mSelectAll(tbl)
put "Arquivos total: " & mSelectCount(tbl)
closeFile(f)
set f = 0
set tbl = 0
set dbObj = 0
set ClassDbe = 0
end
on importaReferencias
Set ClassDbe = Xtra "V12Dbe"
set dbObj = new(ClassDbe,the moviePath & "search.v12","ReadWrite","no")
if NOT objectP(dbObj) then
Alert("Cannot open database: search.v12")
exit
end if
set ClassTable = Xtra "V12Table"
set tbl = new(ClassTable,mGetRef(dbObj),"referencias")
set f = new( xtra "fileio")
openFile(f,the moviePath & "Convertidos/referen.txt", 1)
set fLen = getLength(f)
set counter = 0
repeat while getPosition(f) < fLen-2
set pal to leAteFimDeLinha(f)
set arq to leAteFimDeLinha(f)
set media to leAteFimDeLinha(f)
mAddRecord(tbl)
mSetField(tbl,"palNum", pal)
mSetField(tbl,"arqNum", arq)
mSetField(tbl,"mediaNum", media)
mUpdateRecord(tbl)
set counter = counter + 1
if counter mod 1000 = 0 then put counter & " registros"
end repeat
put "Referencias " & counter
mGoFirst(tbl)
mSelect(tbl)
put "Referencias total: " & mSelectCount(tbl)
closeFile(f)
set f = 0
set tbl = 0
set dbObj = 0
set ClassDbe = 0
end